from flask import request,make_response
from flask_restful import Resource
def bytes2human(n):
    symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
    prefix = {}
    for i, s in enumerate(symbols):
        prefix[s] = 1 << (i + 1) * 10
    for s in reversed(symbols):
        if n >= prefix[s]:
            value = float(n) / prefix[s]
            return '%.1f%s' % (value,s)
    return '%sB' % n

def get_port_params(attr):
    print(request.headers.get("Content-Type"))
    if (request.headers.get("Content-Type").find('application/x-www-form-urlencoded')) >= 0:
        return request.form.get(attr)
    elif request.headers.get("Content-Type").find("application/json") >= 0:
        return request.get_json()[attr]
    else:
        return request.args.get(attr)